/**
 * 预约项目管理初始化
 */
var ReservationsProject = {
    id: "ReservationsProjectTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ReservationsProject.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: '预约项目', field: 'reservationsProject', align: 'center', valign: 'middle', sortable: true},
        {title: '排序',visible: false, field: 'num', align: 'center', valign: 'middle', sortable: true},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true}];
};

/**
 * 检查是否选中
 */
ReservationsProject.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ReservationsProject.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加预约项目
 */
ReservationsProject.openAddReservationsProject = function () {
    var index = layer.open({
        type: 2,
        title: '添加预约项目',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservationsProject/reservationsProject_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看预约项目详情
 */
ReservationsProject.openReservationsProjectDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '预约项目详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/reservationsProject/reservationsProject_update/' + ReservationsProject.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除预约项目
 */
ReservationsProject.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/reservationsProject/delete/" + this.seItem.id, function (data) {
            Feng.success("删除成功!");
            ReservationsProject.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
};


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
ReservationsProject.formParams = function () {
    var queryData = {};
    queryData['reservationsProject'] = $("#reservationsProject").val();
    return queryData;
}

ReservationsProject.resetSearch = function () {
    $("#reservationsProject").val("");
    ReservationsProject.search();
};

/**
 * 查询列表
 */
ReservationsProject.search = function () {
    ReservationsProject.table.refresh({query: ReservationsProject.formParams()});
};

$(function () {
    var defaultColunms = ReservationsProject.initColumn();
    var table = new BSTable(ReservationsProject.id, "/reservationsProject/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(ReservationsProject.formParams());
    ReservationsProject.table = table.init();
    ReservationsProject.table = table;
});
